/**
 * (C) Copyright 2010, 2011 upTick Pty Ltd
 *
 * Licensed under the terms of the GNU General Public License version 3
 * as published by the Free Software Foundation. You may obtain a copy of the
 * License at: http://www.gnu.org/copyleft/gpl.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.gwtcx.sample.serendipity.client.gin;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.SimpleEventBus;
import com.google.inject.Singleton;
import com.gwtcx.client.NameTokens;
import com.gwtcx.client.presenter.AdminGatekeeper;
import com.gwtcx.client.presenter.LoggedInGatekeeper;
import com.gwtcx.sample.serendipity.client.place.DefaultPlace;
import com.gwtcx.sample.serendipity.client.place.SerendipityPlaceManager;
import com.gwtcx.sample.serendipity.client.presenter.SerendipityErrorPagePresenter;
import com.gwtcx.sample.serendipity.client.presenter.SerendipitySignInPagePresenter;
import com.gwtcx.sample.serendipity.client.view.SerendipityErrorPageView;
import com.gwtcx.sample.serendipity.client.view.SerendipitySignInPageView;
import com.gwtplatform.dispatch.shared.SecurityCookie;
import com.gwtplatform.mvp.client.DefaultProxyFailureHandler;
import com.gwtplatform.mvp.client.RootPresenter;
import com.gwtplatform.mvp.client.gin.AbstractPresenterModule;
import com.gwtplatform.mvp.client.proxy.ParameterTokenFormatter;
import com.gwtplatform.mvp.client.proxy.PlaceManager;
import com.gwtplatform.mvp.client.proxy.ProxyFailureHandler;
import com.gwtplatform.mvp.client.proxy.TokenFormatter;

public class SerendipityClientModule extends AbstractPresenterModule {

  @Override
  protected void configure() {
    // Singletons
    bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
    bind(PlaceManager.class).to(SerendipityPlaceManager.class).in(Singleton.class);
    bind(TokenFormatter.class).to(ParameterTokenFormatter.class).in(Singleton.class);
    bind(RootPresenter.class).asEagerSingleton();
    bind(ProxyFailureHandler.class).to(DefaultProxyFailureHandler.class).in(Singleton.class);
    
    bindConstant().annotatedWith(DefaultPlace.class).to(NameTokens.signInPage);
    
    bindPresenter(SerendipityErrorPagePresenter.class, SerendipityErrorPagePresenter.MyView.class,
            SerendipityErrorPageView.class, SerendipityErrorPagePresenter.MyProxy.class);
    
    bindPresenter(SerendipitySignInPagePresenter.class, SerendipitySignInPagePresenter.MyView.class,
            SerendipitySignInPageView.class, SerendipitySignInPagePresenter.MyProxy.class);

    bind(LoggedInGatekeeper.class).in(Singleton.class);
    bind(AdminGatekeeper.class).in(Singleton.class);
  }
}
